package com.bruce.pattern.structural.composite;

import org.junit.Test;

/**
 * Created by bruce on 2018/11/5 23:08
 */
public class MainTest {

    // A 类包含B类的集合
    //可以认为A类和B类是同一类,可以只用组合模式,做相同类型的操作,例如课程目录类和课程类都有打印的功能
    @Test
    public void test(){
        Course linuxCourse = new Course("linux课程", 34.5);
        Course winCourse = new Course("windows课程", 55.5);

        CourseCatalog javaCatalog = new CourseCatalog("Java课程目录",2);
        Course java1 = new Course("Java基础",15);
        Course java2 = new Course("Java高级",25);
        Course java3 = new Course("Java设计模式",39);

        javaCatalog.add(java1);
        javaCatalog.add(java2);
        javaCatalog.add(java3);

        CourseCatalog mainCatalog = new CourseCatalog("所有课程目录",1);
        mainCatalog.add(linuxCourse);
        mainCatalog.add(winCourse);
        mainCatalog.add(javaCatalog);

        mainCatalog.print();



    }








}
